// pages/member/member.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    appurl: app.apiurl,
apiimg: app.apiimg,
    login:false,
    yonghu:'',
    gglist:'',
    gglist1:'',
    ggid:'',
    qiandao:false,
    list1:'',
    list2:'',
    list3:'',
    yindao1:false,
    yindao2:false,
    yindao3:false,
    yindao4:false,
    yindao5:false,
    xin_huiyuan:false,
    bm_status:'0',
    weidenglu:false,
    bm_wztzs_status: '0',
    xydb_pm_status: '0',
    day_sign_status:'0'
  },
  z_shezi(){
    wx.navigateTo({
      url: '/pages/shezi/shezi',
    })
  },
  z_shezi1(){
    wx.navigateTo({
      url: '/packageA/pages/shezi/shezi?other_member_id=200',
    })
  },
  z_open(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/signAdd',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
          qiandao:true
         })
        //  _this.z_qiandao()
      }
    })
  },
  z_close(){
    this.setData({
      qiandao:false,
      yindao1:false,
      yindao2:false,
      yindao3:false
    })
    this.z_yonghu()
  },
  z_close1(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
      "yd_status":'1'
    }
    wx.request({
      url: app.apiurl + 'api/member/upMyYd',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
          yindao1:false,
         })
      }
    })
  },
  z_close2(){
    this.setData({
      yindao1:false,
    })
    wx.setStorageSync("xin_huiyuan", 'false')
    this.z_yonghu()
    wx.redirectTo({
      url: '/pages/index/index',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (wx.getStorageSync("user_token") == "") {
      this.setData({
        weidenglu:true
      })
    } else {
      this.setData({
        weidenglu:false
      })
    }
  },
z_denglu(){
  wx.reLaunch({
    url: '/pages/login/login'
  });
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.z_yonghu()
    this.guanggao1()
    // this.z_qiandao()
    this.z_peizhi()
    this.z_jilu4()
    this.z_idxgg()
  },
  z_idxgg() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/home/index',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          idx_gg: res.data.data,
          xydb_pm_status: res.data.data.xydb_pm_status,
          bm_wztzs_status: res.data.data.bm_wztzs_status,
          day_sign_status: res.data.data.day_sign_status,
          xydb_pm: res.data.data.xydb_pm
        })
      }
    })
  },
  z_yonghu(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/myInfo',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        if(res.data.code == '1001'){
          _this.setData({
            login:true,
            yonghu:res.data.data
          })
        }
       if(wx.getStorageSync("xin_huiyuan") == 'true'){
        _this.setData({
          xin_huiyuan:true,
          yindao1:true
        })
      } else if(wx.getStorageSync("xin_huiyuan") == 'false'){
        _this.setData({
          xin_huiyuan:false
        })
      }
      }
    })
  },
  z_peizhi() {
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/configBase',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          peizhi:res.data.data
        })
      }
    })
  },
  z_jilu4(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token")
    }
    wx.request({
      url: app.apiurl + 'api/member_tj/tjBmStatus',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          bm_status:res.data.data.bm_status
        })
      }
    })
   },
  guanggao1(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advertPage',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        console.log(res.data.data)
         _this.guanggao2()
         _this.guanggao3()
      }
    })
  },
  guanggao2(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advert?page_id=5',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           gglist:res.data.data[0]
         })
      }
    })
  },
  z_kvlianjia(e){
    let _this = this
    let link_url = e.currentTarget.dataset.url
    let id = e.currentTarget.dataset.url
    if(link_url != undefined){
      wx.navigateTo({
        url: link_url,
      })
    }
  },
  guanggao3(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advert?page_id=6',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           gglist1:res.data.data[0]
         })
      }
    })
  },
  z_qiandao(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/signRecord',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           list1:res.data.data.last_bag,
           list2:res.data.data.cur_bag,
           list3:res.data.data.tom_bag
         })
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})